package com.mirabelle.juice.model;

import java.io.Serializable;
import javax.persistence.*;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the collection database table.
 * 
 */
@Entity
@Table(name="collection")
public class Collection implements Serializable {
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String comment;
	private Date created;
	private Date modified;
	private String name;
	private Integer rating;
	private Author author;
	private List<Recipe> recipes;

	public Collection() {
	}
	
	@Id
	@SequenceGenerator(name="COLLECTION_ID_GENERATOR", sequenceName="SEQ_COLLECTION_ID", allocationSize = 1)
	@GeneratedValue(strategy=GenerationType.IDENTITY, generator="COLLECTION_ID_GENERATOR")
	@Column(unique=true, nullable=false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}


	@Column(length=2147483647)
	public String getComment() {
		return this.comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}


	@Temporal(TemporalType.DATE)
	@Column(nullable=false)
	public Date getCreated() {
		return this.created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}


	@Temporal(TemporalType.DATE)
	public Date getModified() {
		return this.modified;
	}

	public void setModified(Date modified) {
		this.modified = modified;
	}


	@Column(nullable=false, length=255)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	//bi-directional many-to-one association to Author
	@ManyToOne
	@JoinColumn(name="author_id", nullable=false)
	public Author getAuthor() {
		return this.author;
	}

	public void setAuthor(Author author) {
		this.author = author;
	}

	public Integer getRating() {
		return this.rating;
	}

	public void setRating(Integer rating) {
		this.rating = rating;
	}


	//bi-directional many-to-one association to Recipe
	@OneToMany(mappedBy="collection")
	public List<Recipe> getRecipes() {
		return this.recipes;
	}

	public void setRecipes(List<Recipe> recipes) {
		this.recipes = recipes;
	}

	public Recipe addRecipe(Recipe recipe) {
		getRecipes().add(recipe);
		recipe.setCollection(this);

		return recipe;
	}

	public Recipe removeRecipe(Recipe recipe) {
		getRecipes().remove(recipe);
		recipe.setCollection(null);

		return recipe;
	}

}